<?php

    require_once(dirname(__FILE__).'/global.inc');

    $pageindex = 2;
    $prevpage = '/infomat/index.php';
    $nextpage = '/infomat/select_ticket.php'; //?code=".$patient->id;
    $nextbutton_action = 'checkcode();';
    $selectedrowcolor = 'yellow'; //"#0692e1";

    require_once(dirname(__FILE__).'/patient.inc'); // подключение модуля определения пациента

    global $patient;
    $mikron->Cache->setCache('patient_id', $patient->id);
    $mikron->Cache->setCache('patient_cardid', $patient->cardid);
    $mikron->Cache->setCache('patient_fio', $patient->fio);
    $mikron->Cache->setCache('patient_birthday', $patient->birthday);
    $mikron->Cache->setCache('patient_cardnumber', $patient->cardnumber);
    $mikron->Cache->setCache('patient_state', $patient->state);
    $mikron->Cache->setCache('patient_errortext', $patient->errortext);

    $speccode = '';
    require_once(dirname(__FILE__).'/schedule.inc');
    LoadShedules(null, $datebegin, $dateend);

?>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr height="*">
    <td width="90%" height="*" align="center" style="height: 95%;">

            <?php
            // Вывод расписания врачей
            $postcnt = 0;
            $pg = 0;
            foreach($ched->items() as $item)
            {
                if($postcnt%constant('POST_PER_PAGE')==0)
                {
                    if($postcnt>0)
                    {
                        $pg++;
                        ?></table></DIV><?php
                    }
                    ?>
                    <div id="postpage<?php echo $pg;?>" style="<?php if($pg>0){?>display: none;<?php }?>">
                    <table width="100%" border="0" class="wintable" cellspacing="0" cellpadding="0">
                            <TR style="position:relative; top:expression(this.offsetParent.scrollTop);">
                            <TD class="wincap1" width="8">Участок</TD>
                            <TD class="wincap2" width="*">Специальность</TD>
                            <TD class="wincap2" style="white-space:nowrap;">Ф.И.О. специалиста</TD>
                            </TR>
                    <?php
                }
                ?>
                    <TR <?php if((string)$item->id == (string)$speccode){?>bgColor="<?php echo $selectedrowcolor;?>"<?php }?>
                        onmousedown="javascript: selectrow(this, '<?php echo $item->id;?>');">
                        <TD class="wincell1" width="8"><font class="table_text">&nbsp;<?php echo $item->state;?>&nbsp;</font></TD>
                        <TD class="wincell2" width="*">
                            <span style="white-space:nowrap;" class="table_text_grey">
                                <?php echo $item->speciality;?>
                            </span>
                        </TD>
                        <TD class="wincell3" width="45%">
                            <font class="table_text"><?php echo $item->fio;?></font>
                        </TD>
                    </TR>
                <?php
                $postcnt++;
            }
            ?>
            <?php if($postcnt>0){?></table></div><?php }?>

    </td>
    <td style="padding-left: 1em;" rowspan="2">
        <?php require_once(dirname(__FILE__).'/help.inc');
        if(function_exists('showpacientinfo'))
        {
            showpacientinfo();
        }
        ?>
    </td>
</tr>
<tr>
    <td style="height: 5%; vertical-align: bottom; text-align: right; padding-bottom: 1em; ">
            <?php if($postcnt > constant('POST_PER_PAGE'))
            {
                ?>
                <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td class="digitbuttonclass"><?php addbutton('page_prev', 'javascript: movepostpage(-1);', 11);?></td>
                    <td style="vertical-align: middle;"><span id="postpagelabel" class="big_text_green">&nbsp;</span></td>
                    <td class="digitbuttonclass"><?php addbutton('page_next', 'javascript: movepostpage(1);', 12);?></td>
                </tr>
                </table>
                <?php
            }?>
    </td>
</tr>
</table>

<script type="text/javascript">
    var postpagescount = <?php echo $pg+1;?>;
    var currentpostpageindex = 0;
    movepostpage(0);
    function movepostpage(addindex)
    {
        currentpostpageindex += addindex;
        if(currentpostpageindex<0){currentpostpageindex=0;}
        if(currentpostpageindex>=postpagescount){currentpostpageindex=postpagescount-1;}
            showpostpage(currentpostpageindex);
    }
    function showpostpage(index)
    {
        
        var postpagelabelEx = document.getElementById("postpagelabel");
        if(postpagelabelEx != null)
        {
            var x = index+1;
            postpagelabelEx.innerHTML = "&nbsp;"+x+" стр. из "+postpagescount+"&nbsp;";
            for(i = 0; i < postpagescount; i++)
            {
                var postpage = document.getElementById("postpage"+i);
                if(i==index)
                {
                    postpage.style.display = '';
                }
                else
                {
                    postpage.style.display = 'none';                            
                }
            }
        }
    }
    function m_down(obj, char, index)
    {   
        var x = -index*<?php echo $keupad_button_width;?>;
        obj.style.backgroundPosition = x+" -<?php echo $keupad_button_width;?>";
    }

    function m_up(obj, char, index)
    {
        var x = -index*<?php echo $keupad_button_width;?>;
        obj.style.backgroundPosition = x+" top";
    }
</script>
            
<script type="text/javascript">
    
    var selectedrow;
    var selectedid = '<?php echo $speccode;?>';

    function selectrow(row, id)
    {
        if(id == selectedid)
        {
            selectedrow.style.backgroundColor = '#ffffff';
            selectedid = "";
        }
        else
        {
            if (selectedrow != null)
            {
                selectedrow.style.backgroundColor = '#ffffff';
            }
            row.style.backgroundColor = '<?php echo $selectedrowcolor;?>';
            selectedid = id;
            selectedrow = row;
        }
    }

    function checkcode()
    {
        var checked = true;
        if(selectedid==0)
        {
            checked = false;
        }
        if(checked)
        {
            okcode();
        }
        else
        {
            badcode();
        }        
    }
    
    function okcode()
    {
        // Код верный!
        xalert2("ПОДОЖДИТЕ...");
        location.href = "<?php echo $nextpage;?>?speccode="+selectedid;
    }

    function badcode()
    {
        xalert('Выберите специалиста!');
    }

    function movescroll(id, toside)
    {
        var obj = document.getElementById(id);
        obj.scrollTop += 28 * toside;
    }

</script>
    
<?php $mikron->Page->EndBody(); ?>